package com.pgy.backend.mapper;

import com.baomidou.mybatisplus.annotation.TableName;
import com.pgy.backend.entity.GradeRule;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
@TableName("grade_rule")
public interface GradeRuleMapper {

    @Select("select * from grade_rule")
    @Results(id = "resultmap" ,value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "pointer_id",property = "superId"),
            @Result(column = "rule",property = "rule"),
            @Result(column = "grade",property = "grade"),
            @Result(column = "level",property = "level"),
            @Result(column = "rank",property = "rank"),
            @Result(column = "note",property = "note"),
    })
    List<GradeRule> findAll();

    @Update("update grade_rule set grade=#{grade}, pointer_id=#{superId}, level=#{level}, rank=#{rank} where id = #{id}")
    @ResultMap(value = {"resultmap"})
    Integer updateById(GradeRule gradeRule);

    @Select("select * from grade_rule where id=#{id}")
    @ResultMap(value = {"resultmap"})
    GradeRule getById(int id);

    @Insert("insert into grade_rule values(#{rule},grade=#{grade}, pointer_id=#{superId}, level=#{level}, rank=#{rank})")
    @ResultMap(value = {"resultmap"})
    Integer insert(GradeRule gradeRule);

    @Delete("delete from grade_rule where id = #{id}")
    @ResultMap(value = {"resultmap"})
    Integer delete(int id);
}
